import { SystemSetter } from "./SystemSetter";
import { Language } from "../../../../extend/language/Language";
import { DataProvider } from "../../../../fl/data/DataProvider";
import { ResouceConst } from "../../../component/gconst/ResouceConst";
import { GCheckBox } from "../../../../com/mui/controls/GCheckBox";
import { PlayerNumItem } from "./PlayerNumItem";
import { EntityHideSetterItem } from "./EntityHideSetterItem";
import { GScrollPane } from "../../../../com/mui/controls/GScrollPane";
import { ScrollPolicy } from "../../../../fl/controls/ScrollPolicy";
import { GTextFormat } from "../../../common/GTextFormat";
import { ObjCreate } from "../common/ObjCreate";
import { SetterSlider } from "./SetterSlider";
import { SliderEvent } from "../../../../fl/events/SliderEvent";
import { GButton } from "../../../../com/mui/controls/GButton";
import { SoundManager } from "../../../common/sound/SoundManager";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { SystemSetterInfo } from "./SystemSetterInfo";
import { Cache } from "../../cache/Cache";
import { ScaleBitmap } from "../../../../com/mui/display/ScaleBitmap";
type int = number;
//class SystemPanel
    
    export  class SystemPanel /* flash.display.Sprite */
    {
        constructor()
        {
            this._sysSetterInfo = SystemSetter.localSetter;
            this._itemCbArr = [];
            this._itemArr = [{"name":"hideLifeMagic", "label": Language.getString(33003)}, {"name":"hidePlayerName", "label": Language.getString(33004)}, {"name":"hideLightAndEffect", "label": Language.getString(33005)}, {"name":"hideChatNotice", "label": Language.getString(33006)}, {"name":"hideTeamChatBubble", "label": Language.getString(33095)}, {"name":"hideNPCInCrossSpy", "label": Language.getString(33101)}, {"name":"showSkillCdTime", "label": Language.getString(33097)}, {"name":"refuseTrade", "label": Language.getString(33007)}, {"name":"hideAllTitle", "label": Language.getString(71478)}, {"name":"refuseFriend", "label": Language.getString(33008)}, {"name":"refuseTeam", "label": Language.getString(33009)}, {"name":"refuseUnion", "label": Language.getString(33010)}, {"name":"clickToFight", "label": Language.getString(33011)}, {"name":"clickToPick", "label": Language.getString(33012)}, {"name":"hideSysBroadcast", "label": Language.getString(33013)}, {"name":"isLockShortcut", "label": Language.getString(33049)}, {"name":"hideWuxingBeadEffect", "label": Language.getString(33096)}, {"name":"hideFabaoEffect", "label": Language.getString(33098)}, {"name":"hideFootPrint", "label": Language.getString(33099)}, {"name":"notSelectPet", "label": Language.getString(33104)}, {"name":"hideBubble", "label": Language.getString(71460)}, {"name":"hideSurround", "label": Language.getString(71477)}, {"name":"hideWaistBelt", "label": Language.getString(71481)}, {"name":"hideElf", "label": Language.getString(71483)}];
            this._dataProvider = new DataProvider();
            
            this.init();
            return;
        }

        /* internal  */init(): void
        {
            var loc2=null;
            var loc5=0;
            var loc10=null;
            var loc1=ResouceConst.getScaleBitmap("WindowCenterB");
            loc1.x = 3;
            loc1.y = 0;
            loc1.width = 405;
            loc1.height = 295;
            this.addChild(loc1);
            loc2 = new Object /* flash.display.Sprite */();
            addChild(loc2);
            var loc3=0;
            var loc4=0;
            loc5 = this._itemArr.length / 2 - 4;
            var loc6=0;
            while (loc6 < this._itemArr.length) 
            {
                (loc10 = new GCheckBox()).styleName = "GCheckBox";
                loc10.name = this._itemArr[loc6].name;
                loc10.label = this._itemArr[loc6].label;
                loc10.width = 200;
                loc10.selected = false;
                loc10.buttonMode = true;
                loc10.x = loc3;
                loc10.y = loc4;
                loc4 = loc4 + loc10.height + 4;
                loc10.addEventListener(flash.events.Event.CHANGE, this.onItemCbChangeHandler);
                loc2.addChild(loc10);
                this._itemCbArr.push(loc10);
                if (loc6 == loc5) 
                {
                    loc3 = 200;
                    loc4 = 0;
                }
                ++loc6;
            }
            this._playerNumItem = new PlayerNumItem();
            this._playerNumItem.x = 0;
            this._playerNumItem.y = 230;
            loc2.addChild(this._playerNumItem);
            this._entityHideSetterItem = new EntityHideSetterItem();
            this._entityHideSetterItem.x = 0;
            this._entityHideSetterItem.y = 276;
            loc2.addChild(this._entityHideSetterItem);
            this._scrollPane = new GScrollPane();
            this._scrollPane.x = this.firstX;
            this._scrollPane.y = this.firstY;
            this._scrollPane.width = 395;
            this._scrollPane.height = 258;
            this._scrollPane.styleName = "GScrollPane";
            this._scrollPane.verticalScrollPolicy = ScrollPolicy.AUTO;
            this._scrollPane.horizontalScrollPolicy = ScrollPolicy.OFF;
            this._scrollPane.source = loc2;
            this._scrollPane.scrollDrag = false;
            this._scrollPane.setScrollBarSize(19);
            addChild(this._scrollPane);
            this._scrollPane.update();
            this._scrollPane.drawNow();
            this._bottomBg = ResouceConst.getScaleBitmap("WindowCenterB");
            this._bottomBg.width = 390;
            this._bottomBg.height = 30;
            this._bottomBg.x = 10;
            this._bottomBg.y = 260;
            this.addChild(this._bottomBg);
            var loc7=new GTextFormat("", 13, 16777113);
            var loc8=ObjCreate.createTextField(Language.getString(33015), 15, 265, 40, 20, this, loc7);
            var loc9=ObjCreate.createTextField(Language.getString(33016), 215, 265, 40, 20, this, loc7);
            loc8.selectable = false;
            loc9.selectable = false;
            this._musicSlider = new SetterSlider();
            this._musicSlider.x = 50;
            this._musicSlider.y = 271;
            this._musicSlider.setSize(125, 25);
            this._musicSlider.maximum = 1;
            this._musicSlider.value = 0.3;
            this._musicSlider.snapInterval = 0.01;
            this._musicSlider.addEventListener(SliderEvent.CHANGE, this.onMusicChangeHandler);
            this.addChild(this._musicSlider);
            this._effectSoundSlider = new SetterSlider();
            this._effectSoundSlider.x = 250;
            this._effectSoundSlider.y = 271;
            this._effectSoundSlider.setSize(125, 25);
            this._effectSoundSlider.maximum = 1;
            this._effectSoundSlider.value = 0.3;
            this._effectSoundSlider.snapInterval = 0.01;
            this._effectSoundSlider.addEventListener(SliderEvent.CHANGE, this.onEffectSoundChangeHandler);
            this.addChild(this._effectSoundSlider);
            this._noSoundCb = new GCheckBox();
            this._noSoundCb.label = Language.getString(33017);
            this._noSoundCb.styleName = "GCheckBox";
            this._noSoundCb.name = "haveNoSound";
            this._noSoundCb.selected = false;
            this._noSoundCb.buttonMode = true;
            this._noSoundCb.x = 12;
            this._noSoundCb.y = 300;
            this._noSoundCb.addEventListener(flash.events.Event.CHANGE, this.onNoSoundCbChangeHandler);
            this.addChild(this._noSoundCb);
            this._defaultBtn = new GButton();
            this._defaultBtn.label = Language.getString(33018);
            this._defaultBtn.styleName = "Button";
            this._defaultBtn.x = 250;
            this._defaultBtn.y = 300;
            this._defaultBtn.width = 70;
            this._defaultBtn.height = 25;
            this.addChild(this._defaultBtn);
            this._defaultBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onDefaultBtnClickHandler);
            this._saveBtn = new GButton();
            this._saveBtn.label = Language.getString(33019);
            this._saveBtn.styleName = "Button";
            this._saveBtn.x = 330;
            this._saveBtn.y = 300;
            this._saveBtn.width = 70;
            this._saveBtn.height = 25;
            this.addChild(this._saveBtn);
            this._saveBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onSaveBtnClickHandler);
            return;
        }

        /* internal  */onItemCbChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=arg1.target as GCheckBox;
            var loc2=loc1.name;
            var loc3=loc1.selected;
            if (loc2 == "hideLifeMagic" || loc2 == "clickToFight") 
            {
                this._sysSetterInfo.setSystemInfo(loc2, !loc3);
            }
            else 
            {
                this._sysSetterInfo.setSystemInfo(loc2, loc3);
            }
            this._sysSetterInfo.isAlter = true;
            return;
        }

        /* internal  */onMusicChangeHandler(arg1: SliderEvent=null): void
        {
            this._sysSetterInfo.musicVolume = this._musicSlider.value;
            this._noSoundCb.selected = false;
            this._sysSetterInfo.setSystemInfo(this._noSoundCb.name, false);
            SoundManager.instance.musicVolume = this._musicSlider.value;
            this.changeNoSoundBtn();
            return;
        }

        /* internal  */onEffectSoundChangeHandler(arg1: SliderEvent=null): void
        {
            this._sysSetterInfo.effectSoundVolume = this._effectSoundSlider.value;
            this._noSoundCb.selected = false;
            this._sysSetterInfo.setSystemInfo(this._noSoundCb.name, false);
            SoundManager.instance.effectSoundVolune = this._effectSoundSlider.value;
            this.changeNoSoundBtn();
            return;
        }

        /* internal  */onNoSoundCbChangeHandler(arg1: Object /* flash.events.Event */=null): void
        {
            this._sysSetterInfo.setSystemInfo(this._noSoundCb.name, this._noSoundCb.selected);
            if (this._noSoundCb.selected) 
            {
                this._musicSlider.value = 0;
                this._effectSoundSlider.value = 0;
                this._sysSetterInfo.musicVolume = 0;
                this._sysSetterInfo.effectSoundVolume = 0;
            }
            else 
            {
                SystemSetter.currentSetter.musicVolume = 0.3;
                SystemSetter.currentSetter.effectSoundVolume = 0.3;
                var loc1;
                this._sysSetterInfo.musicVolume = loc1 = SystemSetter.currentSetter.musicVolume;
                this._musicSlider.value = loc1;
                this._sysSetterInfo.effectSoundVolume = loc1 = SystemSetter.currentSetter.effectSoundVolume;
                this._effectSoundSlider.value = loc1;
            }
            SoundManager.instance.musicVolume = this._musicSlider.value;
            SoundManager.instance.effectSoundVolune = this._effectSoundSlider.value;
            this.changeNoSoundBtn();
            return;
        }

        /* internal  */changeNoSoundBtn(): void
        {
            if (SystemSetter.currentSetter.haveNoSound != this._noSoundCb.selected) 
            {
                SystemSetter.currentSetter.haveNoSound = this._noSoundCb.selected;
                Dispatcher.dispatchEvent(new DataEvent(EventName.NoSoundBtnShowOrHide, SystemSetter.currentSetter.haveNoSound));
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.SaveForSliderChange));
            return;
        }

        /* internal  */onDefaultBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._sysSetterInfo.isAlter = true;
            var loc1=new SystemSetterInfo();
            SystemSetter.localSetter.copy(loc1);
            Dispatcher.dispatchEvent(new DataEvent(EventName.SaveSystemSetter));
            this.resetPanelItem(loc1.getSetterObject());
            Dispatcher.dispatchEvent(new DataEvent(EventName.NoSoundBtnShowOrHide, SystemSetter.currentSetter.haveNoSound));
            return;
        }

        /* internal  */onSaveBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._sysSetterInfo.roleLife = Cache.instance.autoResumeSet.roleLifeSet;
            this._sysSetterInfo.roleMana = Cache.instance.autoResumeSet.roleManaSet;
            this._sysSetterInfo.petLife = Cache.instance.autoResumeSet.petLifeSet;
            this._sysSetterInfo.petMana = Cache.instance.autoResumeSet.petManaSet;
            this._sysSetterInfo.playerNum = this._playerNumItem.playerNum;
            Dispatcher.dispatchEvent(new DataEvent(EventName.SaveSystemSetter));
            return;
        }

        public resetPanelItem(arg1: Object): void
        {
            var loc1=0;
            if (arg1 == null) 
            {
                return;
            }
            while (loc1 < this._itemCbArr.length) 
            {
                if (this._itemCbArr[loc1].name == "hideLifeMagic" || this._itemCbArr[loc1].name == "clickToFight") 
                {
                    if (arg1[this._itemCbArr[loc1].name] != true) 
                    {
                        this._itemCbArr[loc1].selected = true;
                    }
                    else 
                    {
                        this._itemCbArr[loc1].selected = false;
                    }
                }
                else 
                {
                    this._itemCbArr[loc1].selected = arg1[this._itemCbArr[loc1].name];
                }
                ++loc1;
            }
            this._playerNumItem.playerNum = SystemSetter.currentSetter.playerNum;
            this._entityHideSetterItem.entityHideSetting = SystemSetter.currentSetter.hidePlayerPetType;
            this._noSoundCb.selected = SystemSetter.currentSetter.haveNoSound;
            this._musicSlider.value = SystemSetter.currentSetter.musicVolume;
            this._effectSoundSlider.value = SystemSetter.currentSetter.effectSoundVolume;
            SoundManager.instance.musicVolume = this._musicSlider.value;
            SoundManager.instance.effectSoundVolune = this._effectSoundSlider.value;
            return;
        }

        public get musicVolume(): number
        {
            return this._musicSlider.value;
        }

        public get effectSountVolume(): number
        {
            return this._effectSoundSlider.value;
        }

        public get haveNoSound(): Boolean
        {
            return this._noSoundCb.selected;
        }

        public set haveNoSound(arg1: Boolean)
        {
            this._noSoundCb.selected = arg1;
            this.onNoSoundCbChangeHandler();
            return;
        }

        /* internal */ /* const */firstX: int=15;

        /* internal */ /* const */firstY: int=2;

        /* internal */ /* var */_sysSetterInfo: SystemSetterInfo;

        /* internal */ /* var */_scrollPane: GScrollPane;

        /* internal */ /* var */_bottomBg: ScaleBitmap;

        /* internal */ /* var */_defaultBtn: GButton;

        /* internal */ /* var */_saveBtn: GButton;

        /* internal */ /* var */_noSoundCb: GCheckBox;

        /* internal */ /* var */_musicSlider: SetterSlider;

        /* internal */ /* var */_effectSoundSlider: SetterSlider;

        /* internal */ /* var */_playerNumItem: PlayerNumItem;

        /* internal */ /* var */_entityHideSetterItem: EntityHideSetterItem;

        /* internal */ /* var */_itemCbArr: Array<any>;

        /* internal */ /* var */_itemArr: Array<any>;

        /* internal */ /* var */_dataProvider: DataProvider;
    }
